<?php
/**
 * Created by PhpStorm.
 * User: Antique
 * Date: 2021/12/10
 * Time: 下午 08:28
 */

namespace test\primary;

class set_cookie
{
    function set_cookie($md5, $username, $pwd,$time)
    {
        setcookie('Token', $md5, $time, '/');
        $this->save_cookie($md5, $username, $pwd);
    }
//    function set_cookie_life(){
//        //set_cookie_over_time 是cookie的有效时间
//        $set_cookie_over_time = 2000;
//        setcookie('cookie_expire', $cookie_expire, time() + $set_cookie_over_time,'/');
//
//    }
    function save_cookie($md5, $username, $pwd)
    {
        $conn = new \mysqli();
        $conn->connect('127.0.0.1', 'root', '123456', 'userinfo');
        sql_action::set_conn($conn);
        if (!empty($conn->connect_error)) {
            echo '数据库开启异常，请重试';
        }
        $sql = ('update user_info set cookie=\'' . $md5 . '\' where Account=\'' . $username . '\' and pwd=\'' . $pwd . '\'');
        $save_test = sql_action::change($sql);
    }
    function clear_cookie(){
        setcookie('Token', null, null, '/');

    }
}